<template>
  <div style="margin-top: 60px; margin-left: 330px; width: 400px; height: 500px; border: 0 solid red;">
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
      <el-form-item label="ID">
        <el-input v-model="ruleForm.id" readonly></el-input>
      </el-form-item>
      <el-form-item label="维修状态" prop="status">
        <el-radio-group v-model="ruleForm.status" size="medium">
          <el-radio-button label="待处理">待处理</el-radio-button>
          <el-radio-button label="处理中">处理中</el-radio-button>
          <el-radio-button label="已完成">已完成</el-radio-button>
        </el-radio-group>
      </el-form-item>
<!--      <el-form-item label="申请人" prop="applicant_name">-->
<!--        <el-input v-model="ruleForm.applicantName"></el-input>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="申请人电话" prop="applicant_telephone">-->
<!--        <el-input v-model="ruleForm.applicantTelephone"></el-input>-->
<!--      </el-form-item>-->
      <el-form-item label="维修人员姓名" prop="repair_personnel_name">
        <el-input v-model="ruleForm.repairPersonnelName"></el-input>
      </el-form-item>
      <el-form-item label="维修人员电话" prop="repair_personnel_telephone">
        <el-input v-model="ruleForm.repairPersonnelTelephone"></el-input>
      </el-form-item>
      <el-form-item label="开始时间" prop="start_time">
        <el-date-picker v-model="ruleForm.startTime" type="datetime" placeholder="请选择开始时间" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="end_time">
        <el-date-picker v-model="ruleForm.endTime" type="datetime" placeholder="请选择结束时间" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
      </el-form-item>

      <el-form-item label="维修备注" prop="remarks">
        <el-input v-model="ruleForm.remarks"></el-input>
      </el-form-item>
      <!-- 其他表单项根据 maintenance 表的字段添加 -->

      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">立即修改</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>


</template>

<script>
export default {
  data() {
    return {
      i:  0,
      category: null,
      ruleForm: {
        dormitoryNumber: '', // 对应 maintenance 表的公寓号字段
        status: '',           // 对应 maintenance 表的维修状态字段
        applicantName: '',   // 对应 maintenance 表的申请人字段
        applicantTelephone: '', // 对应 maintenance 表的申请人电话字段
        repairPersonnelName: '', // 对应 maintenance 表的维修人员姓名字段
        repairPersonnelTelephone: '', // 对应 maintenance 表的维修人员电话字段
        startTime: '',       // 对应 maintenance 表的开始时间字段
        endTime: '',         // 对应 maintenance 表的结束时间字段
        remarks: ''           // 对应 maintenance 表的维修备注字段
      },
      dormitoryAdminList: '', // 用于存储管理员列表，具体的数据结构根据实际情况修改
      rules: {
        status: [
          { required: true, message: '请输入维修状态', trigger: 'blur' }
        ],
      }
    };
  },
  methods: {
    submitForm(formName) {
      const _this = this
      this.$refs[formName].validate((valid) => {
        if (valid) {
          axios.put('http://localhost:9090/maintenance/update', _this.ruleForm).then(function (resp) {
            if (resp.data.code === 0) {
              _this.$alert(_this.ruleForm.id + '修改成功', '', {
                confirmButtonText: '确定',
                callback: action => {
                  _this.$router.push('/MaintenanceManagement')
                }
              });
            }
          })
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  },
  created() {
    const _this = this
    axios.get('http://localhost:9090/maintenance/list').then(function (resp) {
      _this.dormitoryAdminList = resp.data.data
    })
    axios.get('http://localhost:9090/maintenance/findById/' + _this.$route.query.id).then(function (resp) {
      _this.ruleForm = resp.data.data
    })
  }
}
</script>
